/**
 * 
 */
package fr.cephb.joperon.core;

import java.util.List;



import com.sleepycat.db.DatabaseEntry;
import com.sleepycat.db.DatabaseException;


import fr.cephb.joperon.core.bio.Chromosome;
import fr.cephb.joperon.core.bio.Organism;

/**
 * A Specialized OperonDBSingleValue<Fid,?>
 * for a database using a {@link Fid} as a <b>Key</b>
 *
 */
public abstract class OperonDBUniqFid<V> extends OperonDBSingleValue<Fid,V>
	{
	/**
	 * @param operon
	 */
	public OperonDBUniqFid(Operon operon) {
		super(operon);
		}

	@Override
	public Fid keyFromString(String s)
		{
		return new Fid(s);
		}

	@Override
	protected DatabaseEntry keyToEntry(Fid key) throws DatabaseException {
		return new DatabaseEntry(key.as0EndedByteArray());
	}


	@Override
	public Fid readKey(DatabaseEntry key, DatabaseEntry data)
			throws DatabaseException {
		return new Fid(key);
	}
	
	/** get the organisme for this database */
	public abstract Organism getOrganism();
	
	
	/** list all the <b>Values</b> between the given range */
	public ValueIterator listBetween(Chromosome chr,int start,int end )  throws DatabaseException
		{
		FidEntriesIterator iter= new FidEntriesIterator(getOrganism(),chr,start,end);
		return new ValueIterator(iter);
		}
	
	/** list all the <b>Values</b> on the given chromosome 
	 * @param chr the chromosome
	 * */
	public ValueIterator list(Chromosome chr)  throws DatabaseException
		{
		return listBetween(chr,0,Fid.MAX_VALUE);
		}
	
	/** get all the <b>Values</b> on the given chromosome
	 * @param the chromosome
	 * 
	 *  */
	public List<V> get(Chromosome chr)  throws DatabaseException
		{
		return list(chr).asList();
		}
}
